<?php
// +----------------------------------------------------------------------
// | wttai [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.wttai.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 老司机 <wutongtai@wttai.com> <http://www.wttai.com>
// +----------------------------------------------------------------------

namespace Home\Controller;
use OT\DataDictionary;

/**
 * 留言控制器
 */
class LiuYanController extends HomeController {
	
	/**
	 * 接收留言
	 */
	 public function receive(){
	 	$phone=I('post.phone');//手机号
	 	$name=I('post.name');//手机号
		$content=I('post.content','','strip_tags');//内容
		$rand=I('post.rand','','intval');//验证码
		
		if(!preg_match("/^1[34578]\d{9}$/", $phone)){
			return $this->ajaxReturn(array('state'=>0,'text'=>'手机号错误'));
		}
		$code=D('Common/Code');
		//获取验证码
		$result=$code->newest($phone,1);
		
		if(!$result){
			return $this->ajaxReturn(array('state'=>0,'text'=>'没有找到验证码'));
		}
		
		$rand='验证码：'.$rand.'，全球原创设计师圆梦台！关注官方微信【wttai8844】，发现更多精彩内容！[梧桐珆]';
		//验证验证码
		$rand=$code->verification($rand,$result);
		if($rand[0]!=200){
			return $this->ajaxReturn(array('state'=>0,'text'=>$rand[1]));
		}
		$res=D('Common/Message')->add_liuyan($phone,$content,$name);
		if($res){
		    return $this->ajaxReturn(array('state'=>1,'text'=>'留言成功'));
		}else{
		    return $this->ajaxReturn(array('state'=>0,'text'=>'留言失败'));
		}
		
	 }
	 
}